package views;

import java.awt.BorderLayout;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import presenters.RevenueReportPresenter;

public class RevenueReportPanel extends JPanel {

		private static final long serialVersionUID = 3960536754643630799L;
		JTable table;
		private RevenueReportPresenter myPresenter;

		public RevenueReportPanel() {
			String[] columnNames = {"Vehicle Sno",
	                "Type",
	                "Car Model",
	                "Reservation Revenue",
	                "Late Fees Revenue",
			};
			
			Object[][] data = {
					{"1","1","1","1","1"}
				};
			
			table = new JTable(data, columnNames);
			add(new JScrollPane(table), BorderLayout.CENTER);
			myPresenter = new RevenueReportPresenter(this);
		}
		
		public RevenueReportPresenter getMyPresenter() {
			return myPresenter;
		}

		public void addData(ResultSet rs) {
			Object[][] addInData;
			ArrayList<Object> newData = new ArrayList<Object>();
			try {
				rs.first();
				String[] columnNames = {"Vehicle ID Num", "Type", "Car Model", "Reservation Revenue", "Late Fees Revenue"};
				
				String carSno = rs.getString(columnNames[0]);
				String carType = rs.getString(columnNames[1]);
				String carModel = rs.getString(columnNames[2]);
				String resRev = rs.getString(columnNames[3]);
				String lateFeeRev = rs.getString(columnNames[4]);
				System.out.println(carSno + "\t" + carType + "\t" + carModel + "\t" + resRev + "\t" + lateFeeRev);
				newData.add(carSno);
				newData.add(carType);
				newData.add(carModel);
				newData.add(resRev);
				newData.add(lateFeeRev);
				/*
				while(rs.next()) {
				String carSno = rs.getString("VEHICLE_SNO");
				String carType = rs.getString("TYPE");
				String carModel = rs.getString("CAR_MODEL");
				String resRev = rs.getString("RESERVATION_REV");
				String lateFeeRev = rs.getString("LATE_FEE_REV");
				newData.add(carSno);
				newData.add(carType);
				newData.add(carModel);
				newData.add(resRev);
				newData.add(lateFeeRev);
				}*/
				
			addInData = new Object[newData.size()/5][4];
			int k = 0;
			for (int i = 0; i < newData.size()/5; i++)
			{
				for (int j = 0; j < 5; j++)
				{
					if(j==5) System.out.println("J = 5");
					addInData[i][j] = newData.get(k);
					k++;
				}
			}
			
			table = new JTable(addInData, columnNames);
			}
			catch(SQLException e) {
				e.printStackTrace();
			}
		revalidate();
			
			
		}
		
		public void displayData(ResultSet rs) {
			
		}
}